<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/21
 * Time: 16:56
 */

namespace osc\admin\controller;


use osc\common\controller\AdminBase;
use think\Db;
use think\Request;
use osc\common\service\Excel;

class Programme extends AdminBase
{
    protected function _initialize(){
        parent::_initialize();
        $this->assign('breadcrumb1','提货赠送申请');
        $this->assign('breadcrumb2','申请赠送列表');
        $this->assign('breadcrumb3','申请赠送审核');
        $this->assign('breadcrumb4','凭证赠送初审');
        $this->assign('breadcrumb5','凭证赠送终审');

    }


    /**
     * 收益列表
     * @return mixed
     */
    public function index(){
        $param=input('param.');
        $map = null;
        if(!empty($param['username'])){
            $map['username'] = $param['username'];
        }
        if(!empty($param['sub_date'])){
            $map["sub_date"] = $param['sub_date'];
        }
        if(!empty($param['exchange_id'])){
            $map['exchange_id'] = $param['exchange_id'];
        }
        if(!empty($param['variety_id'])){
            $map['variety_id'] = $param['variety_id'];
        }
        if(!empty($param['time_day'])){
            $map['time_day'] = $param['time_day'];
        }
        if(!empty($param['state'])){
            if($param['state'] != 6){
                $map['state'] = $param['state']-1;
                $map['abn_state'] = 0;
            }else{
                $map['abn_state'] = ['>',0];
            }
        }

//        print_r($map);exit;
        $list = Db::name('programme')
            ->where($map)
			->order('id desc')
            ->paginate(10,false, [
                'query' => Request::instance()->param(),//不丢失已存在的url参数
            ]);

        $page = $list->render();

        $num = Db::name('programme')->where($map)->sum('num');
        $number = Db::name('programme')->where($map)->where('abn_state = 0')->sum('number');
        $price = Db::name('programme')->where($map)->where('abn_state = 0')->sum('number*price');

        //查询交易所
        $exchange = Db::name('exchange_house')->where('state',1)->select();

        $variety = Db::name('exchage_variety')->where('state',1)->select();

        $config = Db::name('config')->where('name','PICK_UP_QUOTA')->find();

        $this->assign('num',$num);
        $this->assign('config',$config);
        $this->assign('number',$number);
        $this->assign('price',$price);
        $this->assign('variety',$variety);
        $this->assign('exchange',$exchange);

        $this->assign('list',$list);
        $this->assign('page',$page);
        return $this->fetch();
    }

    /**
     * 新增修改提货赠送方案每日限制名额
     * @return array
     */
    public function pick_config(){
        if($this->request->isPost()){
            $data = $this->request->param();

            $config = Db::name('config')->where('name','PICK_UP_QUOTA')->find();

            if($config){
                $res = Db::name('config')->where('name','PICK_UP_QUOTA')->update(['value'=>$data['value']]);
                if($res){
                    return ['success'=>'修改成功'];
                }else{
                    return ['success'=>'修改失败'];
                }
            }else{
                $map = [
                    'name'          => 'PICK_UP_QUOTA',
                    'value'         => $data['value'],
                    'info'          => '提货赠送方案每日限制名额',
                    'module'        => 'mobile',
                    'module_name'   => '移动端',
                    'status'        => 1,
                ];

                $red = Db::name('config')->insert($map);

                if($red){
                    return ['success'=>'新增成功'];
                }else{
                    return ['success'=>'新增失败'];
                }
            }
        }
    }

    /**
     * 申请审核
     * @return mixed
     */
    public function audit(){
        $param=input('param.');
        $map = null;
        if(!empty($param['username'])){
            $map['username'] = $param['username'];
        }
        if(!empty($param['sub_date'])){
            $map["sub_date"] = $param['sub_date'];
        }
        if(!empty($param['exchange_id'])){
            $map['exchange_id'] = $param['exchange_id'];
        }
        if(!empty($param['variety_id'])){
            $map['variety_id'] = $param['variety_id'];
        }
        if(!empty($param['time_day'])){
            $map['time_day'] = $param['time_day'];
        }

//        print_r($map);exit;
        $list = Db::name('programme')
            ->where($map)
            ->where('state=0 and abn_state=0')
            ->order('id desc')
            ->paginate(10,false, [
                'query' => Request::instance()->param(),//不丢失已存在的url参数
            ]);

        $page = $list->render();

        $sum = Db::name('programme')->where($map)->where('state',0)->sum('num');

        //查询交易所
        $exchange = Db::name('exchange_house')->where('state',1)->select();

        $variety = Db::name('exchage_variety')->where('state',1)->select();

        $this->assign('sum',$sum);
        $this->assign('variety',$variety);
        $this->assign('exchange',$exchange);

        $this->assign('list',$list);
        $this->assign('page',$page);
        return $this->fetch();
    }

    /**
     * 批量审批
     * @throws \Exception
     */
    public function trial_batch(){
        $data = $this->request->post();
        if(!$data){ $this->redirect('programme/audit'); }
        $map = [];
        foreach($data as $key=>$value){
            $map[$key]['id'] = $value;
            $map[$key]['state'] = 1;
            $map[$key]['begin_date'] = date('Y-m-d',time());
            $map[$key]['end_date'] = delayDate(date('Y-m-d',time()),3);
        }
//        unset($map['/admin/programme/trial_batch']);
        $programme = new \osc\admin\model\Programme();
        $res = $programme->saveAll($map);
        if($res){
            foreach($data as $item){

                //发送短信
                $username = Db::name('programme')->where('id',$item)->find();
//                print_r($username['username']);exit;
                $r= osc_service('common','Rang')->sendsms_programme($username['username']);
            }

            $this->redirect('programme/audit');
        }else{
            $this->error('审批失败');
        }
    }


    /**
     * 审核打回
     */
    public function repulse(){
        $data = $this->request->param();

        $map = [
            'abn_state'     => 1
        ];
        $res = Db::name('programme')->where('id',$data['id'])->update($map);
        if($res){
            $this->redirect('programme/audit');
        }else{
            $this->error('打回失败');
        }
    }


    /**
     * 凭证初审列表
     * @return mixed
     */
    public function voucher(){
        $param=input('param.');
        $map = null;
        if(!empty($param['username'])){
            $map['username'] = $param['username'];
        }
        if(!empty($param['sub_date'])){
            $map["sub_date"] = $param['sub_date'];
        }
        if(!empty($param['exchange_id'])){
            $map['exchange_id'] = $param['exchange_id'];
        }
        if(!empty($param['variety_id'])){
            $map['variety_id'] = $param['variety_id'];
        }
        if(!empty($param['time_day'])){
            $map['time_day'] = $param['time_day'];
        }

//        print_r($map);exit;
        $list = Db::name('programme')
            ->where($map)
            ->where('state=2 and abn_state=0')
            ->order('id desc')
            ->paginate(10,false, [
                'query' => Request::instance()->param(),//不丢失已存在的url参数
            ]);

        $page = $list->render();

        $sum = Db::name('programme')->where($map)->where('state',0)->sum('num');

        //查询交易所
        $exchange = Db::name('exchange_house')->where('state',1)->select();

        $variety = Db::name('exchage_variety')->where('state',1)->select();

        $this->assign('sum',$sum);
        $this->assign('variety',$variety);
        $this->assign('exchange',$exchange);

        $this->assign('list',$list);
        $this->assign('page',$page);
        return $this->fetch();
    }


    /**
     * 凭证初审操作
     * @return mixed
     */
    public function voucher_info(){
        if($this->request->isPost()){

            $data = $this->request->param();
            if($data){

                //审核通过
                if($data['checked'] == 1){

                    //价格录入条件

                    $map = [
                        'state'         => 4,
                        'number'        => $data['number'],
                        'price'         => $data['price'],
                        'total'         => $data['total'],
                        'vou_date'      => $data['vou_date']
                    ];

                    if(!empty($data['desc'])) $map['desc'] = $data['desc'];


//                    print_r($data);exit;

                    $res = Db::name('programme')->where('id',$data['id'])->update($map);


                    if($res){

                        $this->redirect('programme/voucher');
                    }else{
                        $this->error('确认失败');
                    }
                }
                //审核不通过
                if($data['checked'] == 2){

                    $map['abn_state'] = 2;

                    if(!empty($data['desc'])) $map['desc'] = $data['desc'];

                    $res = Db::name('programme')->where('id',$data['id'])->update($map);

                    if($res){
                        $this->redirect('programme/voucher');
                    }else{
                        $this->error('打回失败');
                    }
                }

            }else{
                $this->error('提交错误');
            }
        }else{
            $id = $this->request->param('id');

//            print_r($id);exit;
            $info = Db::name('programme')->where('id',$id)->find();
            $img = Db::name('programme_img')->where(['del_id'=>$id,'seq_id'=>1])->select();
//            print_r($img);exit;
            $this->assign('info',$info);
            $this->assign('img',$img);
            $this->assign('crumbs','凭证初审操作');
            return $this->fetch();
        }

    }


    /**
     * 终审列表
     * @return mixed
     */
    public function end_voucher(){
        $param=input('param.');
        $map = null;
        if(!empty($param['username'])){
            $map['username'] = $param['username'];
        }
        if(!empty($param['sub_date'])){
            $map["sub_date"] = $param['sub_date'];
        }
        if(!empty($param['exchange_id'])){
            $map['exchange_id'] = $param['exchange_id'];
        }
        if(!empty($param['variety_id'])){
            $map['variety_id'] = $param['variety_id'];
        }
        if(!empty($param['time_day'])){
            $map['time_day'] = $param['time_day'];
        }

//        print_r($map);exit;
        $list = Db::name('programme')
            ->where($map)
            ->where('state=4  and abn_state=0')
            ->order('id desc')
            ->paginate(10,false, [
                'query' => Request::instance()->param(),//不丢失已存在的url参数
            ]);

        $page = $list->render();

        $sum = Db::name('programme')->where($map)->where('state',0)->sum('num');

        //查询交易所
        $exchange = Db::name('exchange_house')->where('state',1)->select();

        $variety = Db::name('exchage_variety')->where('state',1)->select();

        $this->assign('sum',$sum);
        $this->assign('variety',$variety);
        $this->assign('exchange',$exchange);

        $this->assign('list',$list);
        $this->assign('page',$page);
        return $this->fetch();
    }


    /**
     * 凭证终审操作
     * @return mixed
     */
    public function end_voucher_info(){
        if($this->request->isPost()){

            $data = $this->request->param();
            $res = 0;
            if($data){

                //审核通过
                if($data['checked'] == 1){

                    $map['state'] = 3;

                    $programme = Db::name('programme')->where('id',$data['id'])->find();
                    if($programme['state']==3)
                    {
                         $this->error('不要重复审核');
                    }

                    $user = Db::name('member')->where('username',$programme['username'])->find();

                    if($programme['time_day']==2)
                    {

                        $bao   = round(($programme['total']*0.8)*5,2)/2 + round($programme['total']*0.2,2)/2;
                        $jilt  = round(($programme['total']*0.8)*5,2)/2 + round($programme['total']*0.2,2)/2;
                        $double = $programme['total'];
                        $user1 = Db::name('member')->where('username',$programme['username'])->setInc('bao',$bao);
                        $user2 = Db::name('member')->where('username',$programme['username'])->setInc('jilt',$jilt);
                        $user3 = Db::name('member')->where('username',$programme['username'])->setInc('complex',$double);
                        $res = Db::name('programme')->where('id',$data['id'])->update($map);
                    }

                    if($programme['time_day']==1)
                    {
                        //$bao   = round(($programme['total']*0.8)*5,2);
                        $jilt  = round($programme['total']*0.3,2);
                        //$double = $programme['total'];
                        //$user1 = Db::name('member')->where('username',$programme['username'])->setInc('bao',$bao);
                        $user2 = Db::name('member')->where('username',$programme['username'])->setInc('jilt',$jilt);
                        //$user3 = Db::name('member')->where('username',$programme['username'])->setInc('complex',$double);
                        $res = Db::name('programme')->where('id',$data['id'])->update($map);
                    }

                    //分享奖励
                    $this->bonus($programme['username'],$data['id']);

                    if($res){

                        //修改用户新vip状态
                        $mad = [];
                        if($user['vip_state'] != 1){
                            $mad['vip_state'] = 1;
                        }

                        if($user['user_state'] == 0){
                            $mad['user_state'] = 1;
                        }

                        Db::name('member')->where('username',$programme['username'])->update($mad);

                        //查询当前用户是否拥有申请资格
                        $eligible = Db::name('eligible')->where('username',$programme['username'])->where('state=0')->find();

                        //修改用户申请合约资格
                        if(!$eligible){

                            $mac = [
                                'username' => $programme['username'],
                                'state' => 0
                            ];
                            Db::name('eligible')->insert($mac);
                        }

                        //发送短信
                        

                        $this->redirect('programme/end_voucher');
                    }else{
                        $this->error('确认失败');
                    }
                }
                //打回初审
                if($data['checked'] == 2){

                    $map['state'] = 2;

                    $res = Db::name('programme')->where('id',$data['id'])->update($map);

                    if($res){
                        $this->redirect('programme/end_voucher');
                    }else{
                        $this->error('打回失败');
                    }
                }

            }else{
                $this->error('提交错误');
            }
        }else{
            $id = $this->request->param('id');

            $info = Db::name('programme')->where('id',$id)->find();
            $img = Db::name('programme_img')->where(['del_id'=>$id,'seq_id'=>1])->select();
            $this->assign('info',$info);
            $this->assign('img',$img);
            $this->assign('crumbs','凭证终审操作');
            return $this->fetch();
        }

    }


    /**
     * 导出新自由买卖
     * @throws \think\Exception
     */
    public function export_carried()
    {

        $param = $this->request->param();

        $map = null;
        if(!empty($param['username'])){
            $map['a.username'] = $param['username'];
        }
        if(!empty($param['sub_date'])){
            $map["a.sub_date"] = $param['sub_date'];
        }
        if(!empty($param['exchange_id'])){
            $map['a.exchange_id'] = $param['exchange_id'];
        }
        if(!empty($param['variety_id'])){
            $map['a.variety_id'] = $param['variety_id'];
        }
        if(!empty($param['state'])){
            if($param['state'] != 6){
                $map['a.state'] = $param['state']-1;
                $map['a.abn_state'] = 0;
            }else{
                $map['a.abn_state'] = ['>',0];
            }
        }

        $excel=new Excel();

        $field = [
            "a.id"                  =>"序号",
            "a.username"            =>"用户",
            "b.idcardname"          =>"姓名",
            "a.sub_date"            =>"申请时间",
            "a.exchange_id"         =>"交易所",
            "a.variety_id"          =>"交易品种",
            "a.num"                 =>"申请金额"
        ];

        $list = Db::name('programme a,osc_member b')
            ->where($map)
            ->where('a.state<>3 and a.username=b.username')
            ->field($field)
            ->order('a.id desc')
            ->select();

        foreach($list as $key=>&$value){
            $value['交易所账号'] = get_trade_id($value['用户'],$value['交易所']);
            $value['交易所'] = get_trade_name($value['交易所']);
            $value['交易品种'] = get_variety_name($value['交易品种']);
        }
        $field['a.acc'] = '交易所账号';
        $ft = "提货赠送".date("Y-m-d",time());
//         echo"<pre>";print_r($list);
//         echo"<pre>";print_r($field);exit;
        $excel->setExcelName($ft)
            ->createSheetByList("提货赠送",$list,$field)
            ->downloadExcel();
    }

    /**
     * 导出提货记录
     * @throws \think\Exception
     */
    public function export_audit()
    {

        $param = $this->request->param();

        $map = null;
        if(!empty($param['username'])){
            $map['a.username'] = $param['username'];
        }
        if(!empty($param['sub_date'])){
            $map["a.sub_date"] = $param['sub_date'];
        }
        if(!empty($param['exchange_id'])){
            $map['a.exchange_id'] = $param['exchange_id'];
        }
        if(!empty($param['variety_id'])){
            $map['a.variety_id'] = $param['variety_id'];
        }
        if(!empty($param['state'])){
            if($param['state'] != 6){
                $map['a.state'] = $param['state']-1;
                $map['a.abn_state'] = 0;
            }else{
                $map['a.abn_state'] = ['>',0];
            }
        }

        $excel=new Excel();

        $field = [
            "a.id"                  =>"序号",
            "a.username"            =>"用户",
            "b.idcardname"          =>"姓名",
            "a.sub_date"            =>"申请时间",
            "a.exchange_id"         =>"交易所",
            "a.variety_id"          =>"交易品种",
            "a.num"                 =>"申请金额"
        ];

        $list = Db::name('programme a,osc_member b')
            ->where($map)
            ->where('a.state=0 and a.abn_state=0 and a.username=b.username')
            ->field($field)
            ->order('a.id desc')
            ->select();

        foreach($list as $key=>&$value){
            $value['交易所账号'] = get_trade_id($value['用户'],$value['交易所']);
            $value['交易所'] = get_trade_name($value['交易所']);
            $value['交易品种'] = get_variety_name($value['交易品种']);
        }
        $field['a.acc'] = '交易所账号';
        $ft = "提货赠送".date("Y-m-d",time());
//        echo"<pre>";print_r($list);
//        echo"<pre>";print_r($field);exit;
        $excel->setExcelName($ft)
            ->createSheetByList("提货赠送",$list,$field)
            ->downloadExcel();
    }


    /**
     * 奖励结算
     * @param $username
     * @param $pro_id
     */
    function bonus($username,$pro_id){

        //查询提货赠送方案
        $info = Db::name('programme')->where('id',$pro_id)->find();

        $user = Db::name('member')->where('username',$username)->find();

        //给推荐人奖励
        
        $sharemobile = Db::name('member')->where('username',$user['sharemobile'])->find();

        if($sharemobile){
            if($sharemobile['user_state']>=1)
            {


                $tj_zong = $info['total']*0.10;

                if($sharemobile['bao']>$tj_zong*2)
                {
                    Db::name('member')->where('username',$sharemobile['username'])->setDec('jilt',$tj_zong);
                    Db::name('member')->where('username',$sharemobile['username'])->setInc('jilin_bean',$tj_zong);
                    $bonus['to_username'] = $username;
                    $bonus['username'] = $sharemobile['username'];
                    $bonus['num'] = $tj_zong;
                    $bonus['type'] = 0;
                    $bonus['create_time'] = time();
                    $bonus['remark'] = '释放';

                    Db::name('bonus')->insert($bonus);

                }
                
            }
        }


        /*
        //获取推荐人的推荐人
        if($sharemobile)
        {
             $upper_share = Db::name('member')->where('username',$sharemobile['sharemobile'])->find();


       
            if($upper_share){
                if($upper_share['user_state']>=1)
                {
                    $s1count = Db::name('member')->where('sharemobile',$upper_share['username'])->count();
                    //$s1count = 5;
                    if($s1count>=5)
                    {
                        $tj2_zong = $info['total']*0.10;

                        Db::name('member')->where('username',$upper_share['username'])->setInc('bao',$tj2_zong/2);
                        Db::name('member')->where('username',$upper_share['username'])->setInc('jilt',$tj2_zong/2);

                        $bonus_share1['to_username'] = $username;
                        $bonus_share1['username'] = $upper_share['username'];
                        $bonus_share1['num'] = $tj2_zong;
                        $bonus_share1['type'] = 0;
                        $bonus_share1['create_time'] = time();
                        $bonus_share1['remark'] = '二代推荐';

                        Db::name('bonus')->insert($bonus_share1);

                    }
                }

            }
        }
        */
      
        /*
        //给区域代理奖励
        $area_team = Db::name('agent_area')->where('id6',$user['id6'])->find();

        if($area_team)
        {
            $area_zong = $info['total']*0.05;

            Db::name('member')->where('username',$area_team['username'])->setInc('bao',$area_zong/2);
            Db::name('member')->where('username',$area_team['username'])->setInc('jilt',$area_zong/2);

            $bonus_area['to_username'] = $username;
            $bonus_area['username'] = $area_team['username'];
            $bonus_area['num'] = $area_zong;
            $bonus_area['type'] = 1;
            $bonus_area['create_time'] = time();
            $bonus_area['remark'] = '代理区域';
            Db::name('bonus')->insert($bonus_area);
        }
        */

        
        //给服务中心奖励
        $service = $this->getshareservice($username);



        //
        if($service)
        {
            $team_zong = $info['total']*0.03;
            $team_user = Db::name('member')->where('username',$service)->find();
            if($team_user['bao']>($team_zong*2))
            {
                Db::name('member')->where('username',$service)->setDec('jilt',$team_zong);
                Db::name('member')->where('username',$service)->setInc('jilin_bean',$team_zong);
                $bonus_team['to_username'] = $username;
                $bonus_team['username'] = $service;
                $bonus_team['num'] = $team_zong;
                $bonus_team['type'] = 0;
                $bonus_team['create_time'] = time();
                $bonus_team['remark'] = '服务中心释放';
                Db::name('bonus')->insert($bonus_team);
            }
            

        }
        $service = $this->getshareservice($service);

        if($service)
        {
            $team_zong = $info['total']*0.02;
            $team_user = Db::name('member')->where('username',$service)->find();
            if($team_user['bao']>($team_zong*2))
            {
                Db::name('member')->where('username',$service)->setDec('jilt',$team_zong);
                Db::name('member')->where('username',$service)->setInc('jilin_bean',$team_zong);
                $bonus_team['to_username'] = $username;
                $bonus_team['username'] = $service;
                $bonus_team['num'] = $team_zong;
                $bonus_team['type'] = 0;
                $bonus_team['create_time'] = time();
                $bonus_team['remark'] = '服务中心发展';
                Db::name('bonus')->insert($bonus_team);
            }
            

        }
        
        $team = $this->getshareagent($username);

        if($team)
        {
            $team_zong = $info['total']*0.05;
            $team_user = Db::name('member')->where('username',$team)->find();
            if($team_user['bao']>($team_zong*2))
            {
                Db::name('member')->where('username',$team)->setDec('jilt',$team_zong);
                Db::name('member')->where('username',$team)->setInc('jilin_bean',$team_zong);
                $bonus_team['to_username'] = $username;
                $bonus_team['username'] = $team;
                $bonus_team['num'] = $team_zong;
                $bonus_team['type'] = 1;
                $bonus_team['create_time'] = time();
                $bonus_team['remark'] = '代理释放';
                Db::name('bonus')->insert($bonus_team);
            }
            

        }

        //给代理的代理奖励
        $shareagent = $this->getshareagent($team);
        

        if($shareagent)
        {
            $shareagent_zong = $info['total']*0.02;

            Db::name('member')->where('username',$shareagent)->setDec('jilt',$shareagent_zong);
            Db::name('member')->where('username',$shareagent)->setInc('jilin_bean',$shareagent_zong);
            $bonus_team['to_username'] = $username;
            $bonus_team['username'] = $shareagent;
            $bonus_team['num'] = $shareagent_zong;
            $bonus_team['type'] = 1;
            $bonus_team['create_time'] = time();
            $bonus_team['remark'] = '代理发展释放';
            Db::name('bonus')->insert($bonus_team);
        }

    }

    /**
     * 递归查询代理
     * @param $username
     * @return mixed|null
     */
    function getshareagent($username)
    {

        if(!$username)
        {
            return null;
        }
        $user = Db::name('member')->where('username',$username)->find();

        $shareuser = Db::name('member')->where('username',$user['sharemobile'])->where('user_state >= 2 and user_state <= 6')->find();

//        echo'<pre>';print_r($shareuser);

        $agent = Db::name('agent')->where('username',$user['sharemobile'])->where('state=1 or state = 0')->find();
//        echo'<pre>';print_r($agent);exit;
        if($shareuser)
        {

            return $shareuser['username'];

        }else
        {

            return $this->getshareagent($user['sharemobile']);

        }


    }

    /**
     * 递归查询服务中心
     * @param $username
     * @return mixed|null
     */
    function getshareservice($username)
    {

        if(!$username)
        {
            return null;
        }
        $user = Db::name('member')->where('username',$username)->find();


        $shareuser = Db::name('member')->where('username',$user['sharemobile'])->where('user_state >= 2 and user_state <= 6')->find();

        $shareuser1 = Db::name('member')->where('username',$user['sharemobile'])->where('user_state = 9')->find();
//        echo'<pre>';print_r($shareuser);

        $agent = Db::name('agent')->where('username',$user['sharemobile'])->where('state=1 or state = 0')->find();
//        echo'<pre>';print_r($agent);exit;
        if($shareuser)
        {

            return null;

        }else if($shareuser1)
        {

            return $shareuser1['username'];

        }else
        {
            return $this->getshareservice($user['sharemobile']);
        }


    }


    /**
     * 根据时间和品种获取收盘价
     * @return array
     */
    function get_time_value(){
        if($this->request->isAjax()){
            $param = $this->request->param();

            $param['time'] = date("Y-m-d",strtotime("-1 day",strtotime($param['time'])));

            $res = Db::name('value_config')->where(['dt'=>$param['time'],'variety_id'=>$param['variety']])->find();

            if($res){
                return ['code'=>1,'msg'=>'OK','data'=>$res['rate']];
            }else{
                return ['code'=>0,'msg'=>'未设置收盘价','data'=>false];
            }
        }else{
            return ['code'=>-1,'msg'=>'获取失败','data'=>false];
        }
    }




}